package com.ambow.service.master.sysoperationlog.rest;

import com.ambow.apimodel.common.ResponseResult;
import com.ambow.apimodel.common.Status;
import com.ambow.service.master.sysoperationlog.dto.SysOperationLogDTO;
import com.ambow.service.master.sysoperationlog.service.SysOperationLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping(value = "/sysOperationLog-api")
@Slf4j
@Api(tags = {"SysOperationLogRest"})
public class SysOperationLogRest {
    @Autowired
    private SysOperationLogService sysOperationLogService;

    /**
     * 添加
     * @return
     */
    @RequestMapping(value = "/insertSysOperationLog", method = RequestMethod.POST)
    @ApiOperation(value = "添加", notes = "返回结果,SUCCESS:200,FAILED:500", httpMethod = "POST")
    public ResponseResult<SysOperationLogDTO> insertSysOperationLog(@RequestBody SysOperationLogDTO sysOperationLogDTO) throws Exception {
        ResponseResult<SysOperationLogDTO> result = new ResponseResult<>();
        try {
            int count = sysOperationLogService.insertSysOperationLog(sysOperationLogDTO);
            result.setStatus(Status.SUCCESS);
            result.setCount(count);
            result.setMessage("修改成功");
            return result;
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            result.setStatus(Status.FAILED);
            result.setMessage("执行异常,请重试");
            return result;
        }
    }

    /**
     * 获取SysOperationLog列表
     * @return
     */
    @RequestMapping(value = "/searchSysOperationLog", method = RequestMethod.POST)
    @ApiOperation(value = "获取SysOperationLog列表", notes = "返回结果,SUCCESS:200,FAILED:500", httpMethod = "POST")
    public ResponseResult<List<SysOperationLogDTO>> searchSysOperationLog(@RequestBody SysOperationLogDTO sysOperationLogDTO) throws Exception {
        ResponseResult<List<SysOperationLogDTO>> result = new ResponseResult<>();
        try {
            List<SysOperationLogDTO> entity = sysOperationLogService.searchSysOperationLog(sysOperationLogDTO);
            result.setStatus(Status.SUCCESS);
            result.setData(entity);
            result.setMessage("查询成功");
            return result;
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            result.setStatus(Status.FAILED);
            result.setMessage("执行异常,请重试");
            return result;
        }
    }

}